//
//  STNetworkTool.swift
//  Demo-04-TabBarTest
//
//  Created by 苏统世 on 16/5/13.
//  Copyright © 2016年 SuTon. All rights reserved.
//

import UIKit
import AFNetworking

enum RequestMethod:String{
    case GET = "GET"
    case POST = "POST"
}

class STNetworkTool: NSObject {

    static let netManager:STNetworkTool=STNetworkTool()
    
    private let afnManager:AFHTTPSessionManager={
        let afn = AFHTTPSessionManager(baseURL: NSURL(string: "https://api.weibo.com/"))
        afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        return afn
    }()
    
    /// 封装AFN的GET和POST,通过参数来确定使用GET还是POST
    func request(method: RequestMethod, URLString: String, parameters: AnyObject?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?) {
        if method == RequestMethod.GET {
            afnManager.GET(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        } else {
            afnManager.POST(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
    }
    /// 发送数据
//    func sendData(URLString: String, parameters: AnyObject?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?){
//        
//        afnManager.POST(URLString, parameters: parameters, success: success, failure: failure)
//    }
    
}
